home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS12.ADF / PopCLI / popcli.c < prev    next >
C/C++ Source or Header  |  1986-08-05  |  8KB  |  276 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\ Copyright (c) 1986 The Software Distillery.  All Rights Reserved */
  3. /* |. o.| || This program may not be distributed without the permission of   */
  4. /* | .  | || the authors.                                                    */
  5. /* | o  | ||    Dave Baker     Ed Burnette  Stan Chow    Jay Denebeim        */
  6. /* |  . |//     Gordon Keener  Jack Rouse   John Toebes  Doug Walker         */
  7. /* ======          BBS:(919)-471-6436      VOICE:(919)-469-4210              */ 
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9. /*
  10.  * VERY loosely based on the input.device example by Rob Peck, 12/1/85
  11.  */
  12.  
  13. /* * * * * * * * * INCLUDE FILES * * * * * * * * * * * */
  14. #include <exec/types.h>
  15. #include <exec/nodes.h>
  16. #include <exec/lists.h>
  17. #include <exec/memory.h>
  18. #include <exec/interrupts.h>
  19. #include <exec/ports.h>
  20. #include <exec/libraries.h>
  21. #include <exec/io.h>
  22. #include <exec/tasks.h>
  23. #include <exec/execbase.h>
  24. #include <exec/devices.h>
  25. #include <devices/timer.h>
  26. #include <devices/input.h>
  27. #include <devices/inputevent.h>
  28. #include <intuition/intuition.h>
  29. #include <graphics/gfxmacros.h>
  30. #include <hardware/custom.h>
  31. #include <hardware/dmabits.h>
  32.  
  33. /* * * * * * * * * * * CONSTANTS * * * * * * * * * * * * */
  34. #define TIMEINTERVAL 1L      /* in seconds */
  35. #define DEFLIMIT     120     /* two minute timeout */
  36. #define ESCAPEKEY 0x45
  37. #define DEFCMD    "NEWCLI >NIL:"
  38. #define BANNER "POPCLI by John Toebes - Copyright ⌐ 1986 The Software Distillery\n"
  39. #define BANNER1 " 235 Trillingham Ln, Cary NC 27511  (919)-469-4210   BBS:(919)-471-6436\n"
  40.  
  41. /* * * * * * * * * * * GLOBAL VARIABLES * * * * * * * * * */
  42. struct task          *buddy;
  43. struct Interrupt      handlerStuff;
  44. ULONG                 createclisig;
  45. ULONG                 unblanksig;
  46. struct MemEntry       me[10];
  47. ULONG                 noevents;
  48. struct Screen        *blankscreen;
  49. struct NewScreen      NewScreen = 
  50.    { 0, 0, 320, 200, 1, 0, 1, NULL, CUSTOMSCREEN, NULL, NULL, NULL, NULL };
  51.  
  52. struct IntuitionBase *IntuitionBase = NULL;
  53. struct GfxBase       *GfxBase = NULL;
  54. long                  DOSBase = 0;
  55. extern struct Custom custom;
  56.  
  57. /* * * * * * * * * * * EXTERNAL ROUTINES * * * * * * * * * */
  58. extern APTR             AllocMem();
  59. extern struct MsgPort  *CreatePort();
  60. extern struct IOStdReq *CreateStdIO();
  61. extern struct Screen   *OpenScreen();
  62. extern void             HandlerInterface();
  63. extern struct task     *FindTask();
  64.  
  65. /************************************************************************/
  66. /* the handler subroutine - called through the handler stub             */
  67. /************************************************************************/
  68. struct InputEvent *myhandler(ev, mydata)
  69. struct InputEvent *ev;      /* and a pointer to a list of events */
  70. struct MemEntry *mydata[];  /* system will pass me a pointer to my 
  71.                              * own data space. */
  72.    {
  73.    register struct InputEvent *ep, *laste;
  74.  
  75.    /* run down the list of events to see if they pressed the magic button */
  76.    for (ep = ev, laste = NULL; ep != NULL; ep = ep->ie_NextEvent)
  77.       {
  78.       if ((ep->ie_Class == IECLASS_RAWKEY) &&
  79.           (ep->ie_Code  == ESCAPEKEY)         &&
  80.           (ep->ie_Qualifier & IEQUALIFIER_LCOMMAND))
  81.          {
  82.          /* we can handle this event so take it off the chain */
  83.          if (laste == NULL)
  84.             ev = ep->ie_NextEvent;
  85.          else
  86.             laste->ie_NextEvent = ep->ie_NextEvent;
  87.          /* now tell him to create the new cli */
  88.          Signal(buddy, createclisig);
  89.          }
  90.       else
  91.          laste = ep;
  92.  
  93.       if (ep->ie_Class != IECLASS_TIMER)
  94.          {
  95.          noevents = 0;
  96.          if (blankscreen != NULL)
  97.             Signal(buddy, unblanksig);
  98.          }
  99.       }
  100.  
  101.    /* pass on the pointer to the event */
  102.    return(ev);
  103.    }
  104.  
  105. /************************************************************************/
  106. /* Queue a timer to go off in a given number of seconds                 */
  107. /************************************************************************/
  108. void QueueTimer(tr,seconds)
  109. struct timerequest *tr;
  110. ULONG seconds;
  111.    {
  112.    tr->tr_node.io_Command = TR_ADDREQUEST;   /* add a new timer request */
  113.    tr->tr_time.tv_secs =  seconds;            /* seconds */
  114.    tr->tr_time.tv_micro = 0;
  115.    SendIO( tr );
  116.    }
  117.  
  118. /************************************************************************/
  119. /* the main program to do the popcli stuff                              */
  120. /************************************************************************/
  121. void _main(cmd)
  122. char *cmd;
  123.    {
  124.    long  intlimit = 0;
  125.    ULONG sig, timersig;
  126.    struct timerequest *timerreq;
  127.    struct MsgPort     *timerport;
  128.    struct MsgPort     *inputDevPort;
  129.    struct IOStdReq    *inputRequestBlock;
  130.  
  131.    buddy = FindTask(0);
  132.    noevents = 0;
  133.  
  134.    /* skip over any leading spaces in the command line */
  135.    while(*cmd == ' ')
  136.       cmd++;
  137.  
  138.    /* see if they specified a limit */
  139.    if (*cmd)
  140.       {
  141.       while ((*cmd >= '0') && (*cmd <= '9'))
  142.          intlimit = (intlimit*10) + *cmd++ - '0';
  143.       }
  144.  
  145.    if (intlimit <= 0)
  146.       intlimit = DEFLIMIT;
  147.  
  148.    /* now skip over any more leading spaces */
  149.    while(*cmd == ' ')
  150.       cmd++;
  151.  
  152.    if (*cmd <= ' ')
  153.       cmd = DEFCMD;
  154.  
  155.    /* ugh we are reusing a variable here - so what - it saves bytes */
  156.    sig = Output();
  157.    Write(sig, BANNER, sizeof(BANNER));
  158.    Write(sig, BANNER1, sizeof(BANNER1));
  159. /* if (sig != Input())
  160.       Close(Input());
  161.    Close(sig); */
  162.  
  163.    SetTaskPri( buddy, 20);
  164.  
  165.    if ((inputDevPort = CreatePort(0,0)) == NULL) /* for input device */
  166.       goto abort0;
  167.  
  168.    if ((inputRequestBlock = CreateStdIO(inputDevPort)) == 0)
  169.       goto abort1;
  170.  
  171.    if ((timerport = CreatePort(0,0)) == NULL)
  172.       goto abort1;
  173.  
  174.    if ((timerreq = (struct timerequest *)
  175.                     AllocMem(sizeof(struct timerequest),
  176.                              MEMF_CLEAR | MEMF_PUBLIC)) == NULL)
  177.       goto abort2;
  178.  
  179.    timerreq->tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  180.    timerreq->tr_node.io_Message.mn_Node.ln_Pri = 0;
  181.    timerreq->tr_node.io_Message.mn_ReplyPort = timerport;
  182.  
  183.    if (OpenDevice(TIMERNAME, UNIT_VBLANK, timerreq, 0))
  184.       goto abort;
  185.  
  186.    timersig = (1 << timerport->mp_SigBit);
  187.  
  188.    if ((sig = AllocSignal(-1)) == -1)
  189.       goto abort;
  190.  
  191.    createclisig = 1 << sig;
  192.  
  193.    if ((sig = AllocSignal(-1)) == -1)
  194.       goto abort;
  195.  
  196.    unblanksig = 1 << sig;
  197.  
  198.    if ((GfxBase = (struct GfxBase *)
  199.                   OpenLibrary("graphics.library", 0)) == NULL)
  200.       goto abort;
  201.  
  202.    if ((IntuitionBase = (struct IntuitionBase *)
  203.                         OpenLibrary("intuition.library", 0)) == NULL)
  204.       goto abort;
  205.  
  206.    handlerStuff.is_Data = (APTR)&me[0];
  207.    handlerStuff.is_Code = HandlerInterface;
  208.    handlerStuff.is_Node.ln_Pri = 51;
  209.  
  210.    if (OpenDevice("input.device",0,inputRequestBlock,0))
  211.       goto abort;
  212.  
  213.    inputRequestBlock->io_Command = IND_ADDHANDLER;
  214.    inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  215.  
  216.    DoIO(inputRequestBlock);
  217.  
  218.    QueueTimer(timerreq, TIMEINTERVAL);
  219.  
  220.    for(;;)         /* FOREVER */
  221.       {
  222.       sig = Wait( createclisig | unblanksig | timersig );
  223.  
  224.       if ((sig & unblanksig) && (blankscreen != NULL))
  225.          {
  226.          (void) CloseScreen(blankscreen);
  227.      ON_DISPLAY
  228.          blankscreen = NULL;
  229.          }
  230.  
  231.       if (sig & createclisig)
  232.          {
  233.          WBenchToFront();
  234.          (void)Execute(cmd,0,0);
  235.          }
  236.  
  237.       if (sig & timersig)
  238.          {
  239.          /* get rid of the message */
  240.          (void)GetMsg(timerport);
  241.          QueueTimer(timerreq, TIMEINTERVAL);
  242.  
  243.          if ((noevents++ >= intlimit) && (blankscreen == NULL))
  244.             {
  245.             if ( (blankscreen = OpenScreen(&NewScreen)) != NULL)
  246.                {
  247.                SetRGB4(&blankscreen->ViewPort, 0, 0, 0, 0);
  248.                OFF_DISPLAY
  249.                }
  250.             }
  251.          }
  252.       }
  253.  
  254. abort:
  255.    CloseDevice(timerreq);
  256. abort3:
  257. /* timerreq->tr_node.io_Message.mn_Node.ln_Type = 0xff;
  258.  * timerreq->tr_node.io_Device = (struct Device *) -1;
  259.  * timerreq->tr_node.io_Unit = (struct Unit *) -1;
  260.  */
  261.  
  262.    FreeMem (timerreq, sizeof(struct timerequest));
  263. abort2:
  264.    DeletePort(timerport);
  265. abort1:
  266.    if (IntuitionBase != NULL)
  267.       CloseLibrary(IntuitionBase);
  268.  
  269.    if (GfxBase != NULL)
  270.       CloseLibrary(GfxBase);
  271.  
  272.    DeletePort(inputDevPort);
  273. abort0:
  274.    XCEXIT(-1);
  275.    }
  276.